home *** CD-ROM | disk | FTP | other *** search
- package Common
- {
- import Common.ParticleSystem.Effect;
- import flash.display.Bitmap;
- import flash.display.Loader;
- import flash.display.LoaderInfo;
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.IOErrorEvent;
- import flash.events.ProgressEvent;
- import flash.media.Sound;
- import flash.net.URLLoader;
- import flash.net.URLRequest;
-
- public class ResourceManager
- {
-
- public static const C_MOVIECLIP:* = 2;
-
- public static const C_RES_TYPE_COUNT:* = 6;
-
- public static const C_TEXT:* = 3;
-
- public static const C_PARTICLE:* = 4;
-
- public static const C_SOUND:* = 1;
-
- public static const C_IMAGES:* = 0;
-
- public static const C_XML:* = 5;
-
-
- private var loadStack:Array;
-
- private var sound:Array;
-
- public var TotalLoaded:int = 0;
-
- private var doneLoading:Boolean = false;
-
- private var particleEffects:Array;
-
- private var movieClip:Array;
-
- private var root:String;
-
- internal var _loaders:Array;
-
- private var text:Array;
-
- public var TotalQueued:int = 0;
-
- private var xmls:Array;
-
- private var callbackFunction:Function;
-
- private var images:Array;
-
- public function ResourceManager(param1:String = "")
- {
- images = [];
- sound = [];
- movieClip = [];
- text = [];
- particleEffects = [];
- xmls = [];
- loadStack = [];
- doneLoading = false;
- TotalQueued = 0;
- TotalLoaded = 0;
- _loaders = new Array();
- super();
- this.root = param1;
- }
-
- public function setXMLResource(param1:String, param2:String) : *
- {
- xmls[param1] = new XML(param2);
- }
-
- public function set Root(param1:String) : *
- {
- this.root = param1;
- }
-
- public function queueResourceLoad(param1:String, param2:String, param3:int) : *
- {
- var _loc4_:Object = null;
- if(getResource(param2,param3) != null)
- {
- return;
- }
- (_loc4_ = new Object()).filename = param1;
- _loc4_.resName = param2;
- _loc4_.type = param3;
- loadStack.push(_loc4_);
- ++TotalQueued;
- }
-
- public function handleComplete(param1:Event) : *
- {
- var _loc2_:Object = null;
- var _loc3_:* = undefined;
- _loc2_ = Object(loadStack.shift());
- ++TotalLoaded;
- if(param1.target is URLLoader)
- {
- _loc3_ = param1.target as URLLoader;
- }
- else if(param1.target is Sound)
- {
- _loc3_ = param1.target as Sound;
- }
- else if(param1.target is LoaderInfo)
- {
- if(param1.target.content is Bitmap)
- {
- _loc3_ = param1.target.content as Bitmap;
- }
- else
- {
- _loc3_ = param1.target.content as MovieClip;
- }
- }
- switch(_loc2_.type)
- {
- case C_IMAGES:
- images[_loc2_.resName] = _loc3_;
- break;
- case C_SOUND:
- sound[_loc2_.resName] = _loc3_;
- break;
- case C_MOVIECLIP:
- movieClip[_loc2_.resName] = _loc3_;
- break;
- case C_PARTICLE:
- particleEffects[_loc2_.resName] = Effect.fromXML(new XML(param1.target.data));
- break;
- case C_XML:
- xmls[_loc2_.resName] = new XML(param1.target.data);
- }
- trace("Load Complete: " + _loc2_.resName);
- _loc3_.removeEventListener(Event.COMPLETE,handleComplete);
- loadResource();
- }
-
- public function get DoneLoading() : *
- {
- return doneLoading;
- }
-
- public function set CallbackFunction(param1:Function) : *
- {
- this.callbackFunction = param1;
- }
-
- public function loadResource() : *
- {
- var _loc1_:* = undefined;
- var _loc2_:URLRequest = null;
- doneLoading = false;
- if(loadStack.length == 0)
- {
- _loaders = new Array();
- doneLoading = true;
- if(callbackFunction != null)
- {
- callbackFunction();
- }
- return;
- }
- _loc2_ = new URLRequest((root == "" ? "" : this.root + "/") + loadStack[0].filename);
- if(loadStack[0].type == C_SOUND)
- {
- _loc1_ = new Sound();
- attachEventListener(_loc1_);
- }
- else if(loadStack[0].type == C_TEXT || loadStack[0].type == C_PARTICLE || loadStack[0].type == C_XML)
- {
- _loc1_ = new URLLoader();
- attachEventListener(_loc1_);
- }
- else
- {
- _loc1_ = new Loader();
- attachEventListener(_loc1_.contentLoaderInfo);
- }
- _loc1_.load(_loc2_);
- _loaders.push(_loc1_);
- }
-
- public function progressFunction(param1:ProgressEvent) : *
- {
- }
-
- public function getResource(param1:String, param2:uint) : *
- {
- switch(param2)
- {
- case C_IMAGES:
- return images[param1];
- case C_SOUND:
- return sound[param1];
- case C_MOVIECLIP:
- return movieClip[param1];
- case C_TEXT:
- return text[param1];
- case C_PARTICLE:
- return particleEffects[param1];
- case C_XML:
- return xmls[param1];
- default:
- return;
- }
- }
-
- public function purgeAllResources() : *
- {
- var _loc1_:* = undefined;
- _loc1_ = 0;
- while(_loc1_ < C_RES_TYPE_COUNT)
- {
- purgeResource(_loc1_);
- _loc1_++;
- }
- }
-
- public function purgeResource(param1:int) : *
- {
- var _loc2_:Object = null;
- _loc2_ = null;
- switch(param1)
- {
- case C_IMAGES:
- for(_loc2_ in images)
- {
- images[_loc2_] = null;
- }
- break;
- case C_SOUND:
- for(_loc2_ in sound)
- {
- sound[_loc2_] = null;
- }
- break;
- case C_MOVIECLIP:
- for(_loc2_ in movieClip)
- {
- movieClip[_loc2_] = null;
- }
- break;
- case C_TEXT:
- for(_loc2_ in text)
- {
- text[_loc2_] = null;
- }
- break;
- case C_PARTICLE:
- for(_loc2_ in particleEffects)
- {
- particleEffects[_loc2_] = null;
- }
- break;
- case C_XML:
- for(_loc2_ in xmls)
- {
- xmls[_loc2_] = null;
- }
- }
- }
-
- public function handleIOError(param1:IOErrorEvent) : void
- {
- trace("Load failed: IO error: " + param1.text);
- loadStack.shift();
- ++TotalLoaded;
- loadResource();
- }
-
- private function attachEventListener(param1:EventDispatcher) : *
- {
- param1.addEventListener(Event.COMPLETE,handleComplete);
- param1.addEventListener(IOErrorEvent.IO_ERROR,handleIOError);
- param1.addEventListener(ProgressEvent.PROGRESS,progressFunction);
- }
- }
- }
-